package workexp.alg.question;

import org.junit.Test;

import java.util.*;

public class FirstUniqChar {
    public int firstUniqChar(String s) {
        int result =-1;
        HashMap<Character,Integer> charhash = new HashMap <>(s.length());
        for (int i = 0; i < s.length(); i++) {
            Character tmp = s.charAt(i);
            charhash.put(tmp,charhash.getOrDefault(tmp,0)+1);
        }
        for (int i = 0; i < s.length() ; i++) {
            Integer count = charhash.get(s.charAt(i));
            if(count==1){
                result=i;
                break;
            }
        }
        return result;
    }

    @Test
    public void test(){
        String s = "leetcode";
        int result =  firstUniqChar(s);
        System.out.println(result);
    }
}

